package com.chiyi.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chiyi.bean.TOrder;
import com.chiyi.bean.TProduct;
import com.chiyi.mapper.TOrderMapper;
import com.chiyi.service.OrderService;
import io.seata.spring.annotation.GlobalTransactional;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @date 2021/5/13 17:40
 */
@RestController
@Api(tags = "订单")
@RequestMapping("/order")
public class OrderController {

    @Resource
    private OrderService orderService;
    @Resource
    private TOrderMapper tOrderMapper;

    @ApiOperation("添加订单")
    @GetMapping("/order/add")
    public TOrder add(@RequestParam Integer pid, @RequestParam Integer uid) {
        TOrder tOrder = orderService.add(pid, uid);
        return tOrder;

    }

    @ApiOperation("获取商品信息")
    @GetMapping("/getProductDetail")
    public TProduct getProductDetail(@RequestParam Integer pid) {
        TProduct tProduct = orderService.getProductDetail(pid);
        return tProduct;

    }


    @ApiOperation("获取所有商品信息")
    @GetMapping("/getAllProduct")
    public List<TProduct> getAllProduct() {
        List<TProduct> tProducts = orderService.getAllProduct();
        return tProducts;

    }

    @ApiOperation("获取全部订单")
    @GetMapping("/getAllOrder")
    public List<TOrder> getAllOrder() {
        QueryWrapper qw = new QueryWrapper();
        List<TOrder> list = tOrderMapper.selectList(qw);
        return list;
    }


}
